It is always a good idea to do any data filtering as early as possible. In this example we know that we want the data for particular spatial and temporal extents. We can apply those and other filters using the OWSLib package.
In the below example we are:
choosing the public.eis_fire_perimeter collection
subsetting it by space using the bbox parameter
subsetting it by time using the datetime parameter
filtering for fires over 5km^2 and over 20 days long using the filter parameter. The filter parameter lets us filter by the columns in ‘public.eis_fire_perimeter’ using SQL-style queries.
NOTE: The limit parameter desginates the maximum number of objects the query will return. The default limit is 10, so if we want to all of the fire perimeters within certain conditions, we need to make sure that the limit is large.
perm_results = w.collection_items("public.eis_fire_perimeter", # name of the dataset we want bbox=["-119.5", "36.8", "-118.9", "37.7"], # coordinates of bounding box, datetime=["2020-01-01T00:00:00+00:00/2020-10-31T12:00:00+00:00"], # date range limit=1000, # max number of items returnedfilter="farea>5 AND duration>20", # additional filters based on queryable fields)
The result is a dictionary containing all of the data and some summary fields. We can look at the keys to see what all is in there.
For instance you can check the total number of matched items and make sure that it is equal to the number of returned items. This is how you know that the limit you defined above is high enough.
In addition to all the summary fields, the perm_results dict contains all the data. We can pass the data into geopandas to make it easier to interact with.
Then we’ll use those fields to get most recent fire perimeters and fire lines.
most_recent_time =max(*perm['extent']['temporal']['interval']) print("Most Recent Time =", most_recent_time)## Get the most recent fire perimetersperm_results = w.collection_items("public.eis_fire_perimeter", datetime=most_recent_time, limit=1000,filter="farea>5", )perimeters = gpd.GeoDataFrame.from_features(perm_results['features'])## Get the most recent fire linesperimeter_ids = perimeters.fid.unique()perimeter_ids =",".join(map(str, perimeter_ids)) fline_results = w.collection_items("public.eis_fire_fireline", datetime=most_recent_time, limit=1000,filter="fid IN ("+ perimeter_ids +")"# only the fires from the fire perimeter query above)fline = gpd.GeoDataFrame.from_features(fline_results['features'])